using System;
using System.Collections.Generic;

namespace ADDDF.Infrastructure.Collections
{
    /// <summary>
    /// IEntitySet is an interface for a set data-structure containing entities
    /// in the form of IEntity interface. It supports common operations to find, and
    /// manipulate items in the set.
    /// 
    /// Entity must override Object.Equals() to provide equality check, and override
    /// Object.GetHashCode() to improve search performance.
    /// 
    /// Entity's key should not be changed once it is added into the set, otherwise, 
    /// the behavior is unpredictable.
    /// </summary>
    public interface IEntitySet        
    {
        void FindByKey(object key, out IEntity result);

        void GetAll(out IEnumerable<IEntity> result);

        bool AddAndReplace(IEntity item);

        bool Remove(IEntity item);

        void RemoveAll();

        int Count();

        void Subtract(IEntitySet another, out IEnumerable<IEntity> result);

        void Intersect(IEntitySet another, out IEnumerable<IEntity> result);        
    }

    /// <summary>
    /// IEntitySet is an interface for a set data-structure containing entities
    /// in the form of IEntity interface. It supports common operations to find, and
    /// manipulate items in the set.
    /// </summary>
    /// <typeparam name="T">An instance of IEntity</typeparam>
    public interface IEntitySet<T> : IEntitySet
        where T : IEntity
    {
        T FindByKey(object key);
        
        IEnumerable<T> GetAll();
        
        bool AddAndReplace(T item);

        bool Remove(T item);

        void RemoveAll();

        int Count();

        IEnumerable<T> Subtract(IEntitySet<T> another);

        IEnumerable<T> Intersect(IEntitySet<T> another);
    }
}
